package com.bwf.string;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/5/12 14:42
 * @Copyright 博为峰
 */
public class StringDemo02 {
    public static void main(String[] args) {
//        m1();
//        m2();
//        m3();
        String s = "fsafsdfsadgtrtrtfgdfgdgsgdgsfsfad";
        //统计字符串中fs出现的次数
//        int index = s.indexOf("fs");
//        s.substring(index + "fh".length());

//        index = s.indexOf("fs");
//        s.substring(index + "fh".length());
        int count = 0;
        int index = 0;
        /*while ((index = s.indexOf("fs")) != -1) {
            s = s.substring(index + "fs".length());
            count++;
        }*/
        while ((index = s.indexOf("fs", index)) != -1) {
            index = index + "fs".length();
            count++;
        }
        System.out.println("count = " + count);
    }

    private static void m3() {
        String s1 = "张三,李四,王五";
        String s2 = s1.concat(",赵六");
//        System.out.println("s1 = " + s1);
//        System.out.println("s2 = " + s2);
        String[] strings = s2.split(",");
        String replace = s2.replace(",", ";");
        System.out.println("replace = " + replace);
    }

    //判断
    private static void m2() {
        String s = "abc";
        System.out.println(s.startsWith("ab"));
        System.out.println(s.endsWith("c"));
        System.out.println(s.contains("b"));
        System.out.println(s.equals("abc"));
    }

    //查
    private static void m1() {
        String s = "abcdefghijklmn";
        System.out.println(s.length());//长度
        System.out.println(s.charAt(3));//根据下标返回对应的字符
        System.out.println(s.indexOf("d", 5));//在此对象表示的字符序列中第一次出现该字符的索引；如果未出现该字符，则返回 -1
        System.out.println(s.lastIndexOf("d"));
        System.out.println(s.substring(3));//defghijklmn
        System.out.println(s.substring(3, 5));//de
    }
}
